package xyz.scootaloo.oj.offer;

import xyz.scootaloo.console.app.support.InvokeProxy;
import xyz.scootaloo.oj.ds.ListNode;

import static xyz.scootaloo.oj.offer.P52a.*;

/**
 * @author flutterdash@qq.com
 * @since 2021/3/28 23:24
 */
public class P52b {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode A = headA;
        ListNode B = headB;
        while (A != B) {
            A = A == null ? headB : A.next;
            B = B == null ? headA : B.next;
        }
        return A;
    }

    public static void main(String[] args) {
        P52b p52B = new P52b();
        System.out.println(testA(InvokeProxy.fun(p52B::getIntersectionNode)));
        System.out.println(testB(InvokeProxy.fun(p52B::getIntersectionNode)));
        System.out.println(testC(InvokeProxy.fun(p52B::getIntersectionNode)));
    }

}
